/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejb;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Rob
 */
@Stateless
public class ArticoloNuovoFacade extends AbstractFacade<ArticoloNuovo> implements ArticoloNuovoFacadeLocal {
    @PersistenceContext(unitName = "webApplication-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ArticoloNuovoFacade() {
        super(ArticoloNuovo.class);
    }
    
     public boolean articoloEsistente(ArticoloNuovo art){
        return !(em.createQuery("select object(articoli) from ArticoloNuovo as articoli where UPPER(articoli.id) ='" + art.getId() + "'").getResultList().isEmpty());
    }
    
     public ArticoloNuovo getArticoloNuovo(Long id){
        return (ArticoloNuovo)(em.createQuery("select * from ArticoloNuovo as articoli where UPPER(articoli.id) ='" + id + "'").getSingleResult());
     
     }

     public List<ArticoloNuovo> findArticoliNuovi(String articolo){
         return (em.createQuery("select * from ArticoloNuovo as articoli where UPPER(articoli.nome) LIKE '%" + articolo + "%'").getResultList());
     }

}

